package org.graduates.webapp.actions.course;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.graduates.webapp.actions.BaseAction;
import org.projects.graduates.domain.HomeworkAssignments;
import org.projects.graduates.domain.HomeworkHandin;
import org.projects.graduates.domain.Teaching;
import org.projects.graduates.domain.TimeTable;

import com.opensymphony.xwork2.ActionSupport;

@Action(results = { @Result(name = "input", type = "redirect", location = "course/studied.action", params = { "cid", "${cid}" }) })
public class TimetableViewAction extends BaseAction {

	private static final long serialVersionUID = -189801044115063672L;

	private long tid = 0L;

	private long cid = 0L;

	private TimeTable tt;

	private Teaching teach;

	private HomeworkAssignments ha;

	private HomeworkHandin handin;

	public String execute() {

		if (0L == tid) {
			return ActionSupport.INPUT;
		}

		tt = TimeTable.get(TimeTable.class, tid);

		if (null == tt) {
			return ActionSupport.INPUT;
		}

		teach = Teaching.findBy(tt.getCourse());
		ha = HomeworkAssignments.findby(tt);
		handin = HomeworkHandin.findBy(ha,getCurrentPerson());
		return ActionSupport.SUCCESS;
	}

	public HomeworkHandin getHandin() {
		return handin;
	}

	public void setHandin(HomeworkHandin handin) {
		this.handin = handin;
	}

	public long getTid() {
		return tid;
	}

	public void setTid(long tid) {
		this.tid = tid;
	}

	public TimeTable getTt() {
		return tt;
	}

	public void setTt(TimeTable tt) {
		this.tt = tt;
	}

	public long getCid() {
		return cid;
	}

	public void setCid(long cid) {
		this.cid = cid;
	}

	public Teaching getTeach() {
		return teach;
	}

	public void setTeach(Teaching teach) {
		this.teach = teach;
	}

	public HomeworkAssignments getHa() {
		return ha;
	}

	public void setHa(HomeworkAssignments ha) {
		this.ha = ha;
	}

}
